package pl;

public class SecurityConditionByte {
	
	boolean isUserPinRequired;
	boolean isSecureMessagingRequired;
	boolean isExternalAuthRequiered;
	
	boolean isAccessNotAllowed;
	boolean isAccessFree;

	boolean allConditionsRequired;
	byte userPinIndex;
	
	public SecurityConditionByte(byte val)
	{
		set(val);
	}
	
	public void set(byte value)
	{
		/*0 0 0 0 0 0 0 0 No condition 
		1 1 1 1 1 1 1 1 Never 
		- - - - 0 0 0 0 No reference to a security environment 
		- - - - Not all equal Security environment identifier (SEID byte, see 6.3.4) from one to fourteen
		- - - - 1 1 1 1 Reserved for future use 
		0 - - - - - - - At least one condition 
		1 - - - - - - - All conditions 
		- 1 - - - - - - Secure messaging 
		- - 1 - - - - - External authentication 
		- - - 1 - - - - User authentication (e.g., password) */
		
		if (value == 0x00) 
		{
			isAccessFree = true;
		}
		else if (value == (byte)0xFF) 
		{
			isAccessNotAllowed = true;
		}
		else
		{
			if ((value & 0x80) == 0x80)
			{
				allConditionsRequired = true;
			}
			
			if ((value & 0x40) == 0x40)
			{
				isSecureMessagingRequired = true;
			}
			
			if ((value & 0x20) == 0x20)
			{
				isExternalAuthRequiered = true;
			}
			
			if ((value & 0x10) == 0x10)
			{
				isUserPinRequired = true;	
				userPinIndex = (byte) (value & 0x0F);  // 1 - 14
			}
		}
	}
}
